package com.jy.modules.cims.subsidiary.controller;

import java.io.InputStream;
import java.io.Writer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.jy.modules.cims.common.CimsConstant;
import com.jy.modules.cims.common.controller.CimsBaseController;
import com.jy.modules.cims.common.controller.ExportController.ExportUtil;
import com.jy.modules.cims.common.sysUtils.DateTimeUtils;
import com.jy.modules.cims.common.sysUtils.SearchParamUtil;
import com.jy.modules.cims.component.common.service.TCMmCostPlanService;
import com.jy.modules.cims.component.sysAssist.ExportAndImport;
import com.jy.modules.cims.creditright.service.OrgAccountService;
import com.jy.modules.cims.data.common.dto.TCMmCostPlanDTO;
import com.jy.modules.cims.data.dto.CreditDetailDto;
import com.jy.modules.cims.data.dto.CreditDetailQueryDto;
import com.jy.modules.cims.data.interact.core.loan.request.ReportQueryDTO;
import com.jy.modules.cims.deal.service.DealService;
import com.jy.modules.cims.subsidiary.service.SubsidiaryService;
import com.jy.platform.core.message.DataMsg;
import com.jy.platform.core.message.PageParameter;
import com.jy.platform.core.message.PageUtil;
import com.jy.platform.core.message.QueryReqBean;
import com.jy.platform.restservice.exception.AbaboonException;

/**
 * @classname: SubsidiaryController
 * @description: 定义 合约 控制层
 * @author: dell
 */
@Controller
@Scope("prototype")
@RequestMapping("/tCMmSubsidiary")
public class SubsidiaryController extends CimsBaseController {

    private static final Logger logger = LoggerFactory.getLogger(SubsidiaryController.class);

    @Autowired
    @Qualifier("com.jy.modules.cims.deal.service.DealService")
    public DealService dealService;

    @Autowired
    @Qualifier("com.jy.modules.cims.subsidiary.service.SubsidiaryService")
    public SubsidiaryService subsidiaryService;

    @Autowired
    @Qualifier("com.jy.modules.cims.creditright.service.OrgAccountService")
    private OrgAccountService orgAccountService;
    
    @Autowired
	@Qualifier("com.jy.modules.cims.component.sysAssist.ExportAndImport")
	private ExportAndImport<?> exportAndImportService;
    
    @Autowired
    @Qualifier("com.jy.modules.cims.component.common.service.TCMmCostPlanService")
    private TCMmCostPlanService service;

    /**
     * 通过 Controller 请求 跳转 进入至相关 页面
     */
    @RequestMapping(value = "/prepareExecute/{operate}")
    public ModelAndView execute(@PathVariable("operate") String operate, HttpServletRequest request)
            throws AbaboonException {
        ModelAndView model = new ModelAndView();

        if ("toQuery".equals(operate)) {// 跳转至 新天报表页面
            model.setViewName("cims/subsidiary/queryTCMmStatement");
        } else if ("toBill".equals(operate)) {// 跳转至 机构账单页面
            model.setViewName("cims/subsidiary/queryTCMmCooperorgBill");
        } else if ("toBillPackage".equals(operate)) {// 跳转至 债权包账单页面
            String cooperorgCode = request.getParameter("cooperorgCode");
            String cooperorgName = request.getParameter("cooperorgName");
            String packageName = request.getParameter("packageName");
            model = this.queryOneDTO(cooperorgCode, cooperorgName, packageName);
            model.setViewName("cims/subsidiary/queryTCMmCooperorgBillPackage");
        } else if ("toBillPackageCredit".equals(operate)) {// 跳转至 债权明细账单页面
            String cooperorgCode = request.getParameter("cooperorgCode");
            String cooperorgName = request.getParameter("cooperorgName");
            String packageName = request.getParameter("packageName");
            model = this.queryOneDTO(cooperorgCode, cooperorgName, packageName);
            model.setViewName("cims/subsidiary/queryTCMmCooperorgBillPackageCredit");
        } else if ("toCreditDate".equals(operate)) {// 跳转至 债权明细账单页面
            model.setViewName("cims/subsidiary/queryTCMmCooperorgDateCredit");
        }

        return model;
    }

    /**
     * @author shengzhoutao
     * @description:机构账单查询分页列表
     * @date 2015-03-26 11:21:31
     * @param request
     * @param dto
     * @param dataMsg
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryTCMmCooperorgBill")
    @ResponseBody
    public DataMsg queryTCMmCooperorgBill(HttpServletRequest request, CreditDetailQueryDto dto,
            @ModelAttribute DataMsg dataMsg) throws Exception {

        Map<String, Object> searchParams = new HashMap<String, Object>();
        searchParams.put("dto", dto);
        QueryReqBean params = new QueryReqBean();
        params.setSearchParams(searchParams);
        PageParameter pageInfo = PageUtil.toPageParameter(dataMsg);
        params.setPageParameter(pageInfo);

        List<CreditDetailDto> list = orgAccountService.getCreditValueForOrgByPaging(params.getSearchParams());

        dataMsg.setData(list);
        dataMsg.setTotalRows(pageInfo.getTotalCount());
        return dataMsg;
    }

    /**
     * @author shengzhoutao
     * @description:债权包账单查询分页列表
     * @date 2015-03-25 11:21:31
     * @param request
     * @param dto
     * @param dataMsg
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryTCMmPackageBill")
    @ResponseBody
    public DataMsg queryTCMmPackageBill(HttpServletRequest request, CreditDetailQueryDto dto,
            @ModelAttribute DataMsg dataMsg) throws Exception {

        Map<String, Object> searchParams = new HashMap<String, Object>();
        searchParams.put("dto", dto);
        QueryReqBean params = new QueryReqBean();
        params.setSearchParams(searchParams);
        PageParameter pageInfo = PageUtil.toPageParameter(dataMsg);
        params.setPageParameter(pageInfo);

        List<CreditDetailDto> list = orgAccountService.getCreditValueForPackageByPaging(params.getSearchParams());

        dataMsg.setData(list);
        dataMsg.setTotalRows(pageInfo.getTotalCount());
        return dataMsg;
    }

    /**
     * @author shengzhoutao
     * @description:债权明细查询分页列表
     * @date 2015-03-25 11:21:31
     * @param request
     * @param dto
     * @param dataMsg
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryTCMmCooperorgBillPackageCredit")
    @ResponseBody
    public DataMsg queryTCMmCooperorgBillPackageCredit(HttpServletRequest request, CreditDetailQueryDto dto,
            @ModelAttribute DataMsg dataMsg) throws Exception {

        Map<String, Object> searchParams = new HashMap<String, Object>();
        searchParams.put("dto", dto);
        QueryReqBean params = new QueryReqBean();
        params.setSearchParams(searchParams);
        PageParameter pageInfo = PageUtil.toPageParameter(dataMsg);
        params.setPageParameter(pageInfo);

        List<CreditDetailDto> list = orgAccountService.searchCreditDetailByPaging(params.getSearchParams());

        dataMsg.setData(list);
        dataMsg.setTotalRows(pageInfo.getTotalCount());
        return dataMsg;
    }

    /**
     * @author dell
     * @description:通过主键查询 其明细信息
     * @date 2015-01-06 11:21:31
     * @param id
     * @return
     */
    private ModelAndView queryOneDTO(String cooperorgCode, String cooperorgName, String packageName)
            throws AbaboonException {
        ModelAndView model = new ModelAndView();
        try {
            // 将信息放入 model 以便于传至页面 使用
            model.addObject("cooperorgCode", cooperorgCode);
            model.addObject("cooperorgName", cooperorgName);
            model.addObject("packageName", packageName);
        }
        catch (Exception e) {
            throw new AbaboonException("执行queryOneDTO异常：", e);
        }
        return model;
    }

    /**
     * 导出非代扣主动还款(认款信息)
     * 
     * @title: exportNoWithholdingActiveRepayment
     * @author
     * @description:
     * @date 2015-3-24 上午9:35:58
     * @param request
     * @param response
     * @param dataMsg
     * @throws
     */
    @RequestMapping(value = "/exportNoWithholdingActiveRepayment")
    public ModelAndView exportNoWithholdingActiveRepayment(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute DataMsg dataMsg) {
        String startDate = (String) this.getParameter("startDate");
        String endDate = (String) this.getParameter("endDate");
        String corpOrgCode = (String) this.getParameter("cooperorgCode");
        //dataMsg = super.initDataMsg(dataMsg);
        try {
            ReportQueryDTO reportQueryDTO = new ReportQueryDTO();
            reportQueryDTO.setStartDate(DateTimeUtils.parseDate(startDate, "yyyy-MM-dd"));
            reportQueryDTO.setEndDate(DateTimeUtils.parseDate(endDate, "yyyy-MM-dd"));
            reportQueryDTO.setCorpOrgCode(corpOrgCode);
            List list = subsidiaryService.queryNoWithholdingActiveRepayment(reportQueryDTO);
            ExportAndImport eai = new ExportAndImport();
            String code = "contractNo,borrower,id,repaymentWay,acctBankName,account,succDate,amount";
            String name = "贷款（合同）编号,借款人,身份证号码,还款方式,信托收款专户,信托收款专户账号,交易成功日期,交易金额";
            String fileName = "非代扣主动还款(认款信息)";
            HSSFWorkbook workbook = eai.exportExcelSubsidiary(fileName, code, name, list);
            ExportUtil.write(workbook, fileName, response);
            return null;
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error("执行方法exportNoWithholdingActiveRepayment异常：", e);
            ModelAndView m = new ModelAndView();
            m.setViewName("cims/subsidiary/queryTCMmStatement");
            m.addObject("error", "导出报表异常！");
            return m;
        }
    }

    /**
     * 一次性结清提前还款明细
     * 
     * @title: exportAdvancFinish
     * @author
     * @description:
     * @date 2015-3-24 上午9:35:58
     * @param request
     * @param response
     * @param dataMsg
     * @throws
     */
    @RequestMapping(value = "/exportAdvancFinish")
    public ModelAndView exportAdvancFinish(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute DataMsg dataMsg) {
        String startDate = (String) this.getParameter("startDate");
        String endDate = (String) this.getParameter("endDate");
        String corpOrgCode = (String) this.getParameter("cooperorgCode");
       // dataMsg = super.initDataMsg(dataMsg);
        try {
            ReportQueryDTO reportQueryDTO = new ReportQueryDTO();
            reportQueryDTO.setStartDate(DateTimeUtils.parseDate(startDate,  "yyyy-MM-dd"));
            reportQueryDTO.setEndDate(DateTimeUtils.parseDate(endDate,  "yyyy-MM-dd"));
            reportQueryDTO.setCorpOrgCode(corpOrgCode);
            List list = subsidiaryService.queryAdvancFinish(SearchParamUtil.getSearchParam(reportQueryDTO));
            ExportAndImport eai = new ExportAndImport();
            String code = "contract_No,cust_name,card_id,must_total_amt,total_term,repay_day,fund_date,loan_status,payoff_date,current_term,must_amount,real_amount";
            String name = "贷款（合同）编号,借款人,身份证号码,应还总额,贷款期限,约定还款日,放款日期,提前还款类型,结清日期,结清前已还期数,结清应还金额,结清实际还款额";
            String fileName = "一次性结清提前还款明细";
            HSSFWorkbook workbook = eai.exportExcelSubsidiary(fileName, code, name, list);
            ExportUtil.write(workbook, fileName, response);
            return null;
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error("执行方法exportAdvancFinish异常：", e);
            ModelAndView m = new ModelAndView();
            m.setViewName("cims/subsidiary/queryTCMmStatement");
            m.addObject("error", "导出报表异常！");
            return m;
        }
    }

    /**
     * 银行账户变更
     * 
     * @title: exportBankAcctChange
     * @author
     * @description:
     * @date 2015-3-24 上午9:35:58
     * @param request
     * @param response
     * @param dataMsg
     * @throws
     */
    @RequestMapping(value = "/exportBankAcctChange")
    public ModelAndView exportBankAcctChange(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute DataMsg dataMsg) {
       // String startDate = (String) this.getParameter("startDate");
       // String endDate = (String) this.getParameter("endDate");
        String corpOrgCode = (String) this.getParameter("cooperorgCode");
       // dataMsg = super.initDataMsg(dataMsg);
        try {
            // if(true)throw new Exception();
            ReportQueryDTO reportQueryDTO = new ReportQueryDTO();
            reportQueryDTO.setCorpOrgCode(corpOrgCode);
            List list = subsidiaryService.queryBankAcctChange(SearchParamUtil.getSearchParam(reportQueryDTO));
            ExportAndImport eai = new ExportAndImport();
            String code = "contract_no,cust_name,card_id,channel,new_bank_code,dict_detail_name,new_acct_name,new_acct_no";
            String name = "贷款（合同）编号,客户名称,身份证号码,支付通道,银行编码,银行名称,账户名称,银行卡号";
            String fileName = "银行账户变更";
            HSSFWorkbook workbook = eai.exportExcelSubsidiary(fileName, code, name, list);
            ExportUtil.write(workbook, fileName, response);
            return null;
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error("执行方法exportBankAcctChange异常：", e);
            ModelAndView m = new ModelAndView();
            m.setViewName("cims/subsidiary/queryTCMmStatement");
            m.addObject("error", "导出报表异常！");
            return m;
        }

    }

    /**
     * 预缴提前还款明细
     * 
     * @title: exportAdvanceRepayment
     * @author
     * @description:
     * @date 2015-3-24 上午9:35:58
     * @param request
     * @param response
     * @param dataMsg
     * @throws
     */
    @RequestMapping(value = "/exportAdvanceRepayment")
    public ModelAndView exportAdvanceRepayment(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute DataMsg dataMsg)  throws Exception {
        String startDate = (String) this.getParameter("startDate");
        String endDate = (String) this.getParameter("endDate");
        String corpOrgCode = (String) this.getParameter("cooperorgCode");
       // dataMsg = super.initDataMsg(dataMsg);
        try {
            ReportQueryDTO reportQueryDTO = new ReportQueryDTO();
            reportQueryDTO.setStartDate(DateTimeUtils.parseDate(startDate, "yyyy-MM-dd"));
            reportQueryDTO.setEndDate(DateTimeUtils.parseDate(endDate, "yyyy-MM-dd"));
            reportQueryDTO.setCorpOrgCode(corpOrgCode);
            List list = subsidiaryService.queryAdvanceRepayment(SearchParamUtil.getSearchParam(reportQueryDTO));
            ExportAndImport eai = new ExportAndImport();
            String code = "contract_no,cust_name,card_id,amt,total_term,REPAY_DAY,FUND_DATE,repay_term,balance";
            String name = "贷款（合同）编号,借款人,身份证号码,应还总额,贷款期限,约定还款日,放款日期,预缴前已还期数,预缴金额";
            String fileName = "预缴提前还款明细";
            HSSFWorkbook workbook = eai.exportExcelSubsidiary(fileName, code, name, list);
            ExportUtil.write(workbook, fileName, response);
            return null;
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error("执行方法exportAdvanceRepayment异常：", e);
            ModelAndView m = new ModelAndView();
            m.setViewName("cims/subsidiary/queryTCMmStatement");
            m.addObject("error", "导出报表异常！");
            return m;
        }

    }

    /**
     * 放款前拒绝放贷明细(我司拒绝放款)
     * @title: exportLoanRefused
     * @author
     * @description:
     * @date 2015-3-26 下午7:45:41
     * @param request
     * @param response
     * @param dataMsg
     * @return
     * @throws
     */
    @RequestMapping(value = "/exportLoanRefused")
    public ModelAndView exportLoanRefused(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute DataMsg dataMsg) {
        String startDate = (String) this.getParameter("startDate");
        String endDate = (String) this.getParameter("endDate");
        String corpOrgCode = (String) this.getParameter("cooperorgCode");
        //dataMsg = super.initDataMsg(dataMsg);
        try {
            ReportQueryDTO reportQueryDTO = new ReportQueryDTO();
            reportQueryDTO.setStartDate(DateTimeUtils.parseDate(startDate, "yyyy-MM-dd"));
            reportQueryDTO.setEndDate(DateTimeUtils.parseDate(endDate, "yyyy-MM-dd"));
            reportQueryDTO.setCorpOrgCode(corpOrgCode);
            List list = subsidiaryService.queryRefuseLoan(SearchParamUtil.getSearchParam(reportQueryDTO));
            ExportAndImport eai = new ExportAndImport();
            String code = "contractNo,borrower,id,contract_amount,reason";
            String name = "贷款（合同）编号,借款人,身份证号码,贷款金额,拒绝放贷原因";
            String fileName = "放款前拒绝放贷明细";
            HSSFWorkbook workbook = eai.exportExcelSubsidiary(fileName, code, name, list);
            ExportUtil.write(workbook, fileName, response);
            return null;
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error("执行方法exportLoanRefused异常：", e);
            ModelAndView m = new ModelAndView();
            m.setViewName("cims/subsidiary/queryTCMmStatement");
            m.addObject("error", "导出报表异常！");
            return m;
        }

    }
    
    
    
    /**
     * 非代扣主动还款清单
     * @title: exportRepaymentInfo_XT
     * @author
     * @description:
     * @date 2015-3-26 下午7:45:41
     * @param request
     * @param response
     * @param dataMsg
     * @return
     * @throws
     */
    @RequestMapping(value = "/exportRepaymentInfo_XT")
    public ModelAndView exportRepaymentInfo_XT(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute DataMsg dataMsg) {
        String startDate = (String) this.getParameter("startDate");
        String endDate = (String) this.getParameter("endDate");
        String corpOrgCode = (String) this.getParameter("cooperorgCode");
        //dataMsg = super.initDataMsg(dataMsg);
        try {
            ReportQueryDTO reportQueryDTO = new ReportQueryDTO();
            reportQueryDTO.setStartDate(DateTimeUtils.parseDate(startDate, "yyyy-MM-dd"));
            reportQueryDTO.setEndDate(DateTimeUtils.parseDate(endDate, "yyyy-MM-dd"));
            reportQueryDTO.setCorpOrgCode(corpOrgCode);
            List list = subsidiaryService.queryRepaymentInfo_Xt(SearchParamUtil.getSearchParam(reportQueryDTO));
            ExportAndImport eai = new ExportAndImport();
            String code = "CONTRACT_NO,CUST_NAME,CARD_ID,REPAY_TYPE,REALITY_RECORD_TIME,RECOGNIZE_AMOUNT";
            String name = "合同号,借款人名称,身份证号码,还款方式,交易成功时间,流水交易金额";
            String fileName = "非代扣主动还款清单";
            HSSFWorkbook workbook = eai.exportExcelSubsidiary(fileName, code, name, list);
            ExportUtil.write(workbook, fileName, response);
            return null;
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error("执行方法exportRepaymentInfo_XT异常：", e);
            ModelAndView m = new ModelAndView();
            m.setViewName("cims/subsidiary/queryTCMmStatement");
            m.addObject("error", "导出报表异常！");
            return m;
        }

    }
    
    
    /**
     * 预缴提前还款后提款明细视图
     * @title: exportPrerepayDraw_Detail
     * @author
     * @description:
     * @date 2015-3-26 下午7:45:41
     * @param request
     * @param response
     * @param dataMsg
     * @return
     * @throws
     */
    @RequestMapping(value = "/exportPrerepayDraw_Detail")
    public ModelAndView exportPrerepayDraw_Detail(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute DataMsg dataMsg) {
        String startDate = (String) this.getParameter("startDate");
        String endDate = (String) this.getParameter("endDate");
        String corpOrgCode = (String) this.getParameter("cooperorgCode");
       // dataMsg = super.initDataMsg(dataMsg);
        try {
            ReportQueryDTO reportQueryDTO = new ReportQueryDTO();
            reportQueryDTO.setStartDate(DateTimeUtils.parseDate(startDate, "yyyy-MM-dd"));
            reportQueryDTO.setEndDate(DateTimeUtils.parseDate(endDate, "yyyy-MM-dd"));
            reportQueryDTO.setCorpOrgCode(corpOrgCode);
            List list = subsidiaryService.queryPrerepayDraw_Detail(SearchParamUtil.getSearchParam(reportQueryDTO));
            ExportAndImport eai = new ExportAndImport();
            String code = "CONTRACT_NO,CUST_NAME,CARD_ID,TOTAL_TERM,REPAY_DAY,FUND_DATE,MUST_AMT,INIT_AMOUNT,PAY_TIME,PAY_AMOUNT";
            String name = "合同号,借款人,身份证号码,贷款期限,约定还款日,放款日期,应还总额,预缴余额,提款日期,提现金额";
            String fileName = "预缴提前还款后提款明细视图";
            HSSFWorkbook workbook = eai.exportExcelSubsidiary(fileName, code, name, list);
            ExportUtil.write(workbook, fileName, response);
            return null;
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error("执行方法exportPrerepayDraw_Detail异常：", e);
            ModelAndView m = new ModelAndView();
            m.setViewName("cims/subsidiary/queryTCMmStatement");
            m.addObject("error", "导出报表异常！");
            return m;
        }

    }
    
    /**
     * 辅助功能公共导入方法
     * @param request
     * @param response
     * @param dataMsg
     * @return
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/importDataDetail", method = RequestMethod.POST)
    public void importDataDetail(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute DataMsg dataMsg) throws Exception{
    	Writer out = response.getWriter();
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			// 获取文件流
			MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
			CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest.getFile("file");
			FileItem fileItems = file.getFileItem();
			String fileName = fileItems.getName();
			InputStream inputStream = file.getInputStream();

			Class<?> classObject = TCMmCostPlanDTO.class;
			// 设置需要进行数据转换的格式,map中的KEY值为fieldName
			Map<String, Map> excelColumnsConvertMap = new HashMap<String, Map>();
			Map<String, String> planStatus = new HashMap<String, String>();
			planStatus.put("已结算", "01");
			planStatus.put("未结算", "");
			
			excelColumnsConvertMap.put("planStatus", planStatus);
			String costPlanCode = CimsConstant.COST_PLAN_FILE_EXPORT_CODE;
		    String costPlanName = CimsConstant.COST_PLAN_FILE_EXPORT_NAME;
		    String costPlanImport = CimsConstant.COST_PLAN_FILE_EXPORT_IS;
		    List<TCMmCostPlanDTO> tCMmCostPlanList = (List<TCMmCostPlanDTO>) exportAndImportService.excelImportParameter(inputStream, fileName,costPlanImport, costPlanCode,
		    		costPlanName, classObject, excelColumnsConvertMap);

			if(tCMmCostPlanList.size()>1000){
				throw new Exception("导入数据大于1000条，导入失败！");
			}else{
				service.updateCostPlanData(tCMmCostPlanList);
			}
			
			// 7.回显数据
			result.put("status", "ok");
			out.write(JSON.toJSONString(result));
			inputStream.close();
		} catch (Exception e) {
			e.printStackTrace();
			dataMsg.failed(e.getMessage());
			result.put("status", "error");
			result.put("errorMassage", e.getMessage());
			out.write(JSON.toJSONString(result));
			// throw new
			// Exception(CimsExceptionConstant.IMPORT_EXCEL_FAIL+e.getMessage());
		}finally {
			out.close();
		}

    }    
}
    
